﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using eVoteClient.util;

namespace eVoteClient
{
    public partial class CreatePoll : Form
    {
        public CreatePoll()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var socket = global.socket;

            string msg = "NEW_POL_REQ#" + nameTxt.Text+"#"+studyGroups.Text+"#"+numericUpDown1.Value+"#";

            int day = dateTimePicker1.Value.Day;
            int month = dateTimePicker1.Value.Month;
            int year = dateTimePicker1.Value.Year;

            msg += year + "-" + month + "-" + day;
            msg += "#" + questionTxt.Text;
            for (int i = 0; i < answersTxt.Lines.Length; i++)
                if(!answersTxt.Lines[i].Equals(""))
                    msg += "#" + answersTxt.Lines[i];

            socket.writer.WriteLine(msg);
            socket.writer.Flush();
            string reply = socket.reader.ReadLine();

            if(reply.Split('#')[1].Equals("1"))
                MessageBox.Show("Poll has been created");
            else
                MessageBox.Show("There's problem, poll has not been created");

        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            new Home().Show();
            this.Hide();
        }

        private void CreatePoll_Load(object sender, EventArgs e)
        {
            this.Location = new Point(350, 200);
            this.Size = new Size(572, 324);
        }

    }
}
